package com.example.a12.adapter;

// 使用 Support 库的注解
import android.support.annotation.NonNull;


import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.List;

public class ViewPagerAdapter extends FragmentStateAdapter {
    String titleArr[];
    List<Fragment> fragmentList;

    public ViewPagerAdapter(@NonNull FragmentActivity fragmentActivity,
                            List<Fragment> list, String[] titleAr) {
        super(fragmentActivity);
        fragmentList = list;
        this.titleArr = titleAr;
    }

    @Override
    public int getItemCount() {
        return fragmentList.size();
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragmentList.get(position);
    }

    public CharSequence getTitle(int position) {
        return titleArr[position];
    }
}